import { UserRating, FilterRule, ButtonFilterDependency } from "../common/globalType";
import { computed, ComputedRef } from '@vue/composition-api';

// 导出组合函数
export default function <T extends UserRating>(userRatings: T[], filterDep: ButtonFilterDependency) {
    // 过滤用户评论数组
    const filterUserRatings: ComputedRef<T[]> = computed(() => {
        const type: FilterRule = filterDep.currRule;
        const isFiltertext: boolean = filterDep.isFilterText;
        // 需要检查是否勾选过滤空文本
        const filterUserRatings = isFiltertext
            ? userRatings.filter((rating) => rating.text !== "")
            : userRatings;
        return type == null
            ? filterUserRatings
            : filterUserRatings.filter((rating) => rating.rateType === type);
    });
    return { filterUserRatings };
}
